// webpack/webpack.dev.config.js
//webpack 配置文件
const path = require('path');

//使用webpack-node-externals来排除不需要打包的模块，因为 node 端会自动载入这些包，可以让打包的文件更小。
const nodeExternals = require('webpack-node-externals');

const webpack = require('webpack');
const resolvePath = (pathstr) => path.resolve(__dirname, pathstr);

process.env.BABEL_ENV = 'node';//设置 babel 的运行环境

const isProd=process.env.NODE_ENV==='production';

module.exports = {
  target: 'node', // in order to ignore built-in modules like path, fs, etc.
  entry: resolvePath('../src/server/app/index.js'),//入口文件
  output: {
    filename: 'app.js',
    path: resolvePath('../dist/server')
  },
  externals: [nodeExternals()], // in order to ignore all modules in node_modules folder
  module: {
    rules: [{
      test: /\.jsx?$/,
      loader: 'babel-loader',
      exclude: /node_modules/
    }]
  },
  plugins: [
    new webpack.DefinePlugin({
      '__SERVER__':true
    })
  ]
};
